package com.dbgs.gifdnndklib;

import android.graphics.Bitmap;

/**
 * Created by Administrator on 2017/9/24.
 */

public class GifHandler {
    static {
        System.loadLibrary("gif-lib");
    }
    private long gifPoint;

    public GifHandler(String path) {
        this.gifPoint = load(path);
    }

    public long load(String path) {
        gifPoint=loadGif(path);
        return gifPoint;
    }

    //    long  C 指针
    private   native  long loadGif(String Path);

    private   native  int getWidth(long gifPoint);

    private   native  int getHeight(long gifPoint);

    //绘制函数
    private  native int updateFrame(Bitmap bitmap,long gifPoint);

    public int getWidth() {
        return getWidth(gifPoint);
    }
    public int getHeight() {
        return getHeight(gifPoint);

    }
    public int updateFrame(Bitmap bitmap) {
        return updateFrame(bitmap,gifPoint);
    }
}

/*
*
tv_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                File file = new File(Environment.getExternalStorageDirectory(), "timg.gif");
                gifHandler = new GifHandler(file.getAbsolutePath());
                Log.i("tuch", "ndkLoadGif: " + file.getAbsolutePath());
                //得到gif   width  height  生成Bitmap
                int width = gifHandler.getWidth();
                int height=gifHandler.getHeight();
                bitmap= Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
                int delay=gifHandler.updateFrame(bitmap);
                handler.sendEmptyMessageDelayed(1, delay);
            }
        });

        Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            int delay=gifHandler.updateFrame(bitmap);
            handler.sendEmptyMessageDelayed(1, delay);
            imageView.setImageBitmap(bitmap);
        }
    };
* */